package com.itcast.peft.service.washrule;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.itcast.peft.entity.InteractionReply;
import com.itcast.peft.service.InteractionDataWasher.WashedData;
import com.itcast.peft.service.InteractionDataWasher.WashedDataRule;
/**
 * 
 * 清洗规则：一个问题的总赞数必须大于等于指定的比例
 *
 */
@Component
public class LikedTimesPercentageRule implements WashedDataRule {

    @Value("${interaction.likedtimes.percentage:70}")
    private int percentage;
    
    @Override
    public boolean test(WashedData t) {
         var total = t.getAllReply().stream().mapToInt(InteractionReply::getLikedTimes).sum();
         var referance = t.getPreferanceReply().getLikedTimes();
         var p = referance * 100. / total;
         return p >= percentage;
    }

}
